﻿package org.leles.ui 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Bruno Leles
	 */
	public class MovieCheckBox extends MovieClip
	{
		public static const CHECKED_FRAME:Object = "_checked";
		public static const UNCHECK_FRAME:Object = 1;
		
		protected var _checked:Boolean;
		
		public function MovieCheckBox() 
		{
			super();
			_checked = false;
			
			addEventListener( MouseEvent.CLICK, mouseClick )
			
			if ( stage ) init()
			else addEventListener( Event.ADDED_TO_STAGE, init )
		}
		
		private function mouseClick(e:MouseEvent):void 
		{
			_checked = !_checked;
			goto( _checked ? CHECKED_FRAME : UNCHECK_FRAME );
		}
		
		private function init(e:Event = null):void 
		{
			goto( _checked ? CHECKED_FRAME : UNCHECK_FRAME );
		}
		
		private function goto(frame:Object):void
		{
			gotoAndStop( frame );
		}
		
		public function get checked():Boolean
		{
			return _checked;
		}
	}
	
}